package com.trantor.stockmarketwatch;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class StocksListAdapter extends BaseAdapter {
	private final Context context;
	private final List<StockEntry> stocksList;

	public StocksListAdapter(Context context, List<StockEntry> stocksList) {
		this.context = context;
		this.stocksList = stocksList;
	}
	
	@Override
	public int getCount() {
		return stocksList.size();
	}

	@Override
	public Object getItem(int position) {
		return stocksList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView tv = new TextView(context);
		StockEntry se = stocksList.get(position);
		tv.setText(
				String.format("%s\n%s\n%s\n%s",
						se.getTicker(),
						se.getPrice(),
						se.getChange(),
						se.getPercent_change()));
		return tv;
	}
}
